
#include <stdio.h>
#include <string.h>

const char* types[] = {"Decimal",
                       "Int64",
                       "Int32",
                       "Int16",
                       "SByte",
                       "UInt64",
                       "UInt32",
                       "UInt16",
                       "Byte",
                       "Single",
                       "Double",
					   "String",
                       "Char",
                       "Boolean",
                       "DateTime",
                       "Type"};

int main(int argc, char* argv[])
{
    if(argc < 2) printf("need a parameter for output file.\n");
    else
    {
        FILE* fo = fopen(argv[1], "w");
        fputs("\n'this file is generated by osi/root/codegen/swap/swap.exe"
              "\n'so edit the osi/root/codegen/swap/swap.cpp instead of this file\n"
              "\n\nPublic Module _swap\n\n", fo);
        for(int i = 0; i < sizeof(types) / sizeof(types[0]); i++)
        {
            fprintf(fo,
                    "    Public Sub swap(ByRef x As %s, ByRef y As %s)\n"
                    "        Dim i As %s = Nothing\n"
                    "        i = x\n"
                    "        x = y\n"
                    "        y = i\n"
                    "    End Sub\n\n",
                    types[i], types[i], types[i]);
        }

        fputs("    Public Sub swap(Of T)(ByRef x As T, ByRef y As T)\n"
              "        Dim i As T = Nothing\n"
              "        i = x\n"
              "        x = y\n"
              "        y = i\n"
              "    End Sub\n\n",
              fo);

        fputs("End Module\n", fo);
        fclose(fo);
    }
}
